package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.bean.MediaBean;
import com.cloudsigns.factorymanager2.engineering.bean.PublicationOrderDetailBean;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.DateUtil;

import java.util.List;

/**
 * Created by tony on 2018/5/30.
 */

public class PublicationFeedBackInfoActivity extends Activity implements View.OnClickListener {
    private View rl_back;
    private TextView tv_title;
    private TextView tv_project_name, tv_engineering_name;
    private View ll_content;
    private TextView edt_wentineirong, edt_time;
    private View rl_project;
    private ImageView imgbefor_publication, imgafter_publication, img_picture;
    private ImageView img_feedback;
    private boolean isClick;
    private MediaBean mediaBean;
    private PublicationOrderDetailBean publicationOrderDetailBean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_publication_feedback_info);

        init();

        if (null != getIntent()) {
            publicationOrderDetailBean = (PublicationOrderDetailBean) getIntent().getSerializableExtra(ConstantUtil.KEY_1);
            mediaBean = (MediaBean) getIntent().getSerializableExtra(ConstantUtil.KEY_2);
        }

        initData();


    }

    private void init() {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        rl_project = findViewById(R.id.rl_project);

        tv_project_name = findViewById(R.id.tv_project_name);
        tv_engineering_name = findViewById(R.id.tv_engineering_name);

        edt_wentineirong = findViewById(R.id.edt_wentineirong);
        edt_time = findViewById(R.id.edt_time);

        ll_content = findViewById(R.id.ll_content);

        imgbefor_publication = findViewById(R.id.imgbefor_publication);
        imgafter_publication = findViewById(R.id.imgafter_publication);
        img_picture = findViewById(R.id.img_picture);

        img_feedback = findViewById(R.id.img_feedback);

        tv_title.setText("上刊信息");
        rl_back.setOnClickListener(this);
        rl_project.setOnClickListener(this);
    }

    private void initData() {
        if (null != mediaBean) {
            tv_project_name.setText(mediaBean.getMediaName());
            tv_engineering_name.setText("/" + mediaBean.getNumber());


            List<String> beforePicList = mediaBean.getBeforePicList();
            if (null != beforePicList && beforePicList.size() > 0) {
                Uri uri = Uri.parse(beforePicList.get(0).toString().trim());
                Glide.with(this).load(uri).asBitmap().into(imgbefor_publication);

            }

            List<String> afterPicList = mediaBean.getAfterPicList();
            if (null != afterPicList && afterPicList.size() > 0) {
                Uri uri = Uri.parse(afterPicList.get(0).toString().trim());
                Glide.with(this).load(uri).asBitmap().into(imgafter_publication);
            }

            edt_wentineirong.setText(mediaBean.getUnusualReason());
            edt_time.setText(DateUtil.getYyyy_Mm_Dd(mediaBean.getFeedbackDate()));

            List<String> feedbackPicList = mediaBean.getFeedbackPicList();
            if (null != feedbackPicList && feedbackPicList.size() > 0) {
                Uri uri = Uri.parse(feedbackPicList.get(0).toString().trim());
                Glide.with(this).load(uri).asBitmap().into(img_picture);
            }
        }

        if (mediaBean.getStatus() == CommonEnum.MediaStatus.PROCESSING) {
            img_feedback.setVisibility(View.VISIBLE);
            isClick = true;
        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.PAUSE) {
            img_feedback.setVisibility(View.GONE);
            isClick = false;
        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.PROBLEM_APPEAR) {
            img_feedback.setVisibility(View.VISIBLE);
            isClick = true;
        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.PROBLEM_FEEDBACK) {
            img_feedback.setVisibility(View.VISIBLE);
            isClick = true;
        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.COMPLETE_FEEDBACK) {
            img_feedback.setVisibility(View.GONE);
            isClick = false;
        } else if (mediaBean.getStatus() == CommonEnum.MediaStatus.COMPLETE) {
            img_feedback.setVisibility(View.GONE);
            isClick = false;
        }

    }

    @Override
    public void onClick(View view) {
        Intent mIntent;
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
            case R.id.rl_project:
                if (isClick) {
                   // mIntent = new Intent(this, AddPublicationFeedBackActivity.class);
                    mIntent = new Intent(this, PublicationFeedBackInfoActivity1.class);
                    mIntent.putExtra(ConstantUtil.KEY_1, publicationOrderDetailBean);
                    mIntent.putExtra(ConstantUtil.KEY_2, mediaBean);
                    startActivity(mIntent);
                    finish();
                }

                break;
        }
    }

}
